#include "Latch.h"


Latch::~Latch() = default;

void Latch::count_down(std::ptrdiff_t update) {
    std::lock_guard lock{_mutex};
    _counter -= update;
    if (_counter != 0) {
        return;
    }
    _cv.notify_all();
}

void Latch::wait() const {
    std::unique_lock lock{_mutex};
    _cv.wait(lock, [this](){ return _counter <= 0; });
}
